//
//  HHWDoublePicker.swift
//  Pickers
//
//  Created by 鲁万财 on 15/7/27.
//  Copyright (c) 2015年 鲁万财. All rights reserved.
//

import UIKit

class HHWDoublePicker: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
    
    private var kFillingComponent = 0;
    private var kBreadComponent = 1;
    private var fillingTypes:Array<String> = [];
    private var breadTypes:Array<String> = [];
    
    @IBOutlet weak var doublePicker: UIPickerView!
    
    override func viewDidLoad() {
        super.viewDidLoad();
        
        self.fillingTypes = ["Ham", "Turkey", "Peanut Butter", "Tuna Salad", "Chicken Salad", "Roast Beef", "Vegemite"];
        self.breadTypes = ["White", "Whole Wheat", "Rye", "Sourdough", "Seven Grain"];
    }
    
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 2;
    }
    
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        if(component == self.kBreadComponent) {
            return self.breadTypes.count;
        } else {
            return self.fillingTypes.count;
        }
    }
    
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
        if(component == self.kBreadComponent) {
            return self.breadTypes[row];
        } else {
            return self.fillingTypes[row];
        }
    }
    
    @IBAction func buttonPressed(sender: AnyObject) {
        var fillingRow = self.doublePicker.selectedRowInComponent(self.kFillingComponent);
        var breadRow = self.doublePicker.selectedRowInComponent(self.kBreadComponent);
        var filling = self.fillingTypes[fillingRow];
        var bread = self.breadTypes[breadRow];
        var message = String(format: "Your %@ on %@ bread will be right up.", filling, bread);
        var alert = UIAlertView(title: "Thank you for your order", message: message, delegate: nil, cancelButtonTitle: "Great");
        alert.show();
    }
}
